package com.zhentao.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhentao.mapper.CourseCategoriesMapper;
import com.zhentao.mapper.CoursesMapper;
import com.zhentao.mapper.TeachersMapper;
import com.zhentao.mapper.UsersMapper;
import com.zhentao.pojo.CourseCategories;
import com.zhentao.pojo.Courses;
import com.zhentao.pojo.Teachers;
import com.zhentao.pojo.Users;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 学生管理控制器
 */
@RestController
@RequestMapping("/students")
public class StudentsController {

    @Autowired
     CoursesMapper coursesMapper;

    @Autowired
     TeachersMapper teachersMapper;

    @Autowired
     UsersMapper usersMapper;
     @Autowired
    CourseCategoriesMapper courseCategoriesMapper;
    /**
     * 获取热门课程列表
     * @return 热门课程列表
     */
    @GetMapping("hot-courses")
    public List<Courses> getHotCourses() {
        QueryWrapper<Courses> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", "published");
        List<Courses> courses = coursesMapper.selectList(queryWrapper);
        courses.forEach(c -> {
            Teachers teachers = teachersMapper.selectById(c.getTeacherId());
            Users users = usersMapper.selectById(teachers.getUserId());
            c.setTeacherName(users.getRealName());
            CourseCategories courseCategories = courseCategoriesMapper.selectById(c.getCategoryId());
                c.setCourseName(courseCategories.getName());
        });
        return courses;
    }
//    课程分类
    @PostMapping("allfl")
    private List<CourseCategories> getAllCourses(int id) {
        QueryWrapper<CourseCategories> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("type_id", id);
        List<CourseCategories> courses = courseCategoriesMapper.selectList(queryWrapper);
        return courses;
    }
//    商城

}
